FROM php:7.1.11-fpm-alpine3.4
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

RUN apk add --update nginx supervisor bash 
RUN  apk add zlib-dev libmcrypt-dev
RUN apk --update add openssh openrc 


RUN docker-php-ext-install \
        mcrypt \
        mbstring \
        pdo_mysql \
        zip \
        bcmath \
        iconv

#gd
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
  docker-php-ext-configure gd \
    --with-gd \
    --with-freetype-dir=/usr/include/ \
    --with-png-dir=/usr/include/ \
    --with-jpeg-dir=/usr/include/ && \
  NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
  docker-php-ext-install -j${NPROC} gd && \
  apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev

RUN apk add --no-cache --virtual .build-deps \
    g++ make autoconf


RUN pecl install redis \
    && docker-php-ext-enable redis

# RUN pecl install -o -f redis \
# &&  rm -rf /tmp/pear \
# &&  echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini
RUN apk del --purge .build-deps       

RUN  rm -rf /var/cache/apk/* \
    && chown -R nginx:www-data /var/lib/nginx

RUN mkdir -p /etc/nginx/sites-available && \
	mkdir -p /etc/nginx/sites-enabled && \
	mkdir -p /run/nginx

ADD supervisord.conf /etc/supervisord.conf
ADD nginx.conf /etc/nginx/nginx.conf
# ADD sites/*.conf /etc/nginx/sites-enabled/
ADD sites/default.conf /etc/nginx/sites-enabled/

ADD src/ /var/www/html/



RUN sed -i \
        -e "s/user = www-data/user = nginx/g" \
        -e "s/;listen.mode = 0660/listen.mode = 0666/g" \
        -e "s/;listen.owner = www-data/listen.owner = nginx/g" \
        -e "s/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g" \
        -e "s/^;clear_env = no$/clear_env = no/" \
        /usr/local/etc/php-fpm.d/www.conf

CMD /usr/bin/supervisord -n -c /etc/supervisord.conf



RUN  curl -sS https://install.phpcomposer.com/installer | php -- --install-dir=/usr/local/bin --filename=composer

ADD ./src/eboss.tar.gz /var/www/html/

RUN mv /var/www/html/eboss/.env.docker /var/www/html/eboss/.env


RUN cd /var/www/html/eboss \
    && composer install 


RUN chown nginx:www-data /etc/nginx -R && \
    chown nginx:www-data /run/nginx && \
    chown nginx:www-data /var/www/html -R 




ADD ssh/insecure_id_rsa /tmp/id_rsa
ADD ssh/insecure_id_rsa.pub /tmp/id_rsa.pub


# RUN  rm -f /etc/service/sshd/down && \
#     cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys \
#         && cat /tmp/id_rsa.pub >> /root/.ssh/id_rsa.pub \
#         && cat /tmp/id_rsa >> /root/.ssh/id_rsa \
#         && rm -f /tmp/id_rsa* \
#         && chmod 644 /root/.ssh/authorized_keys /root/.ssh/id_rsa.pub \
#     && chmod 400 /root/.ssh/id_rsa \
 




RUN  sed -i '/\#\!\/bin\/sh/a\php /var/www/html/eboss/artisan config:init' /usr/local/bin/docker-php-entrypoint
# ENTRYPOINT ["docker-php-entrypoint"]

